<style lang="less">
</style>
<template>
  <div class="search">
    <Row>
      <Col>
        <Card>
          <Row>
            <Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
              <Form-item label="车牌号">
                <Input
                  type="text"
                  v-model="searchForm.licnum"
                  clearable
                  placeholder="车牌号"
                  style="width: 160px"
                />
              </Form-item>
              <div class="float-r">
                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                <Button @click="handleReset">重置</Button>
              </div>
            </Form>
          </Row>
          <Row>
            <Alert show-icon>
              已选择
              <span class="select-count">{{selectCount}}</span> 项
              <a class="select-clear" @click="clearSelectAll">清空</a>
            </Alert>
          </Row>
          <Row>
            <Table
              :loading="loading"
              size="small"
              border
              :columns="columns"
              :data="data"
              max-height="500"
              @on-sort-change="changeSort"
              @on-selection-change="showSelect"
              ref="table"
            ></Table>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page
              :current="searchForm.current"
              :total="total"
              :page-size="searchForm.size"
              @on-change="changePage"
              @on-page-size-change="changePageSize"
              :page-size-opts="[10,20,50,100]"
              size="small"
              show-total
              show-elevator
              show-sizer
            ></Page>
          </Row>
        </Card>
      </Col>
    </Row>
  </div>
</template>

<script>
import { getCarTerminalPageList } from "@/api/operate";
import circleLoading from "../../my-components/circle-loading.vue";

export default {
  name: "car-manage",
  components: {
    circleLoading
  },
  data() {
    return {
      drop: false,
      dropDownContent: "展开",
      dropDownIcon: "ios-arrow-down",
      loading: true,
      operationLoading: false,
      selectCount: 0,
      selectList: [],
      searchForm: {
        current: 1,
        size: 20
      },
      submitLoading: false,
      columns: [
        {
          type: "selection",
          width: 60,
          align: "center",
          fixed: "left"
        },
        {
          title: "设备名称",
          key: "deviceName",
          width: 180
        },
        {
          title: "设备编号",
          key: "deviceNum",
          width: 180
        },
        {
          title: "设备型号",
          key: "deviceModel",
          width: 150
        },

        {
          title: "生产厂商",
          key: "manufacturer",
          width: 150
        },
        {
          title: "卡号",
          key: "simCard",
          width: 150
        },
        {
          title: "IMEI",
          key: "imei",
          width: 160
        },
        {
          title: "ICCID",
          key: "iccid",
          width: 200
        },
        {
          title: "出场序列号",
          key: "sn",
          width: 150
        },
        {
          title: "车主姓名",
          key: "username",
          width: 120
        },
        {
          title: "车主联系方式",
          key: "mobile",
          width: 160
        }
      ],
      data: [],
      total: 0
    };
  },
  methods: {
    init() {
      this.getCarTerminalList();
    },
    changePage(v) {
      this.searchForm.current = v;
      this.getCarTerminalList();
      this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.size = v;
      this.getCarTerminalList();
    },
    getCarTerminalList() {
      // 多条件搜索
      this.loading = true;
      getCarTerminalPageList(this.searchForm).then(res => {
        this.loading = false;
        if (res.code == 0) {
          this.data = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    dropDown() {
      if (this.drop) {
        this.dropDownContent = "展开";
        this.dropDownIcon = "ios-arrow-down";
      } else {
        this.dropDownContent = "收起";
        this.dropDownIcon = "ios-arrow-up";
      }
      this.drop = !this.drop;
    },
    handleSearch() {
      this.searchForm.current = 1;
      this.searchForm.size = 20;
      this.getCarList();
    },
    handleReset() {
      this.searchForm.beanName = "";
      this.searchForm.current = 1;
      this.searchForm.size = 20;
      // 重新加载数据
      this.getCarList();
    },
    showSelect(e) {
      this.selectList = e;
      this.selectCount = e.length;
      this.$emit("showSelect", e);
    },
    clearSelectAll() {
      this.$refs.table.selectAll(false);
    }
  },
  mounted() {
    this.init();
  }
};
</script>
